package com.ysstech.valuation.controller;


import com.ysstech.common.annotation.YssLog;
import com.ysstech.common.controller.BaseController;
import com.ysstech.common.util.DateUtil;
import com.ysstech.valuation.entity.Quotation;
import com.ysstech.valuation.service.QuotationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lishuangliang
 * @since 2021-02-22
 */
@Controller
@Slf4j
@Api(tags = "行情信息管理api")
@RequestMapping("/quotation")
public class QuotationController extends BaseController {
    @Autowired
    private QuotationService quotationService;

    /**
     * 通过证券代码和日期获取行情
     *
     * @param securityCode
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "获取证券代码行情信息")
    @YssLog(module = "行情信息管理", remark = "获取证券代码行情信息")
    @PostMapping(value = "/getQuotation")
    @ResponseBody
    public Quotation getQuotation(String securityCode, String fdate) throws Exception {
        return quotationService.getQuotation(securityCode, DateUtil.strToLocalDate(fdate));
    }


    @ApiOperation(value = "获取证券代码行情信息")
    @YssLog(module = "行情信息管理", remark = "获取证券代码行情信息")
    @PostMapping(value = "/queryQuotationCache")
    @ResponseBody
    public Map<String, List<Quotation>> queryQuotationCache(String fdate) throws Exception {
        Map<String, List<Quotation>> map= quotationService.queryQuotationCache(DateUtil.strToLocalDate(fdate));
        return map;
    }
}
